/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ctconsolecheck;

import de.XPortLib.Exceptions.TCPCommunicationException;
import de.XPortLib.Interfaces.XPortControllerIF;
import de.XPortLib.XPortController;

/**
 *
 * @author alex
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
		XPortControllerIF xport = new XPortController();
		xport.setIpAddress("192.168.6.3");
		xport.setPort(10001);
		int retries = 0;
		
		do {
			try {
				int relais = Integer.parseInt(args[0])-1;
				boolean[] status = xport.readRelais();
				if(status[relais]) {
					System.exit(0);
				}
				else System.exit(1);
			}
			catch (TCPCommunicationException ex) {
				if (retries < 5) {	
					retries++;
					try {Thread.sleep(retries * 1000);}
					catch (Exception ex2) {}
				}
				else {
					ex.printStackTrace();
					System.exit(1);
				}
			}
			catch (Exception ex) {
				ex.printStackTrace();
				System.exit(1);
			}
		}
		while (true);
    }
}
